package huawei;

import java.util.Arrays;
import java.util.Comparator;

/**
 * 书籍叠放
 */
public class Q154 {

    public static void main(String[] args) {
        int[][] books = new int[][]{{20,16}, {15,11}, {10,10},{9,10}};

        Arrays.sort(books, (e1, e2) -> e1[0] - e2[0] == 0 ? e1[1] - e2[1] : e1[0] - e2[0]);

        int[] dp = new int[books.length];
        Arrays.fill(dp, 1);// 每本书都可以单独摆放

        for (int i = 1; i < dp.length; i++) {
            for (int j = 0; j < i; j++) {
                if ( books[i][0] > books[j][0] && books[i][1] > books[j][1] ) {
                    dp[i] = Math.max(dp[i], dp[j] + 1);
                    break;
                }
            }
        }

        System.out.println(dp[dp.length - 1]);
    }
}
